"""
main execution entry
"""
import sys

from functions import (
    raw_request,
    system_info,
    restart,
    start,
    stop,
    status,
    get_bios,
    set_bios,
    find_bios,
    reset_bios,
    get_physical_disk,
    create_virtual_disk,
    eject_first_virtual_media,
    inject_first_virtual_media,
    connect_to_first_virtual_media,
    boot_to_cd_once_with_uefi,
    install_os_with_nfs_shared_iso
)
from functions.argument import build_args


# command table to be executed
COMMAND_TABLE = {
    # raw requests
    'raw': raw_request,
    # power [satisfied compatibility]
    'info': system_info,
    'restart': restart,
    'stop': stop,
    'start': start,
    'status': status,
    # bios [satisfied compatibility]
    'getbios': get_bios,
    'setbios': set_bios,
    'findbios': find_bios,
    'resetbios': reset_bios,
    # raid
    'getpd': get_physical_disk,
    'createvd': create_virtual_disk,
    # virtual media
    'ejectvm': eject_first_virtual_media,
    'injectvm': inject_first_virtual_media,
    'connectvm': connect_to_first_virtual_media,
    # boot option
    'boot2cd': boot_to_cd_once_with_uefi,
    # os install
    'osinstall': install_os_with_nfs_shared_iso
}


def execute():
    if len(sys.argv) > 7 and sys.argv[7] == 'raw':
        return COMMAND_TABLE['raw']()
    args = build_args()
    if args.command not in COMMAND_TABLE:
        print('Error command, use -h for manual')
    return COMMAND_TABLE[args.command]()


if __name__ == '__main__':
    execute()
